package com.shujia.sql

import org.apache.spark.{SparkConf, SparkContext}
import com.google.gson.Gson

object Demo2RDDReadJson {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()
      .setMaster("local") //本地运行
      .setAppName("map")

    val sc = new SparkContext(conf)

    val jsonRDD = sc.textFile("data/student.json")

    val studentRDD = jsonRDD.map(line => {
      val gson = new Gson()

      val student = gson.fromJson(line, classOf[Student])

      student
    })

    studentRDD.filter(_.gender.equals("男")).foreach(println)



  }

  case class Student(id: String, name: String, age: Integer, clazz: String, gender: String)

}
